//
//  YDYWelcomeViewController.m
//  DY_Weibo3
//
//  Created by 杨德勇 on 2016/8/21.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

#import "YDYWelcomeViewController.h"
#import "YDYUserAccount.h"

#import <UIImageView+WebCache.h>

@interface YDYWelcomeViewController ()
/*用户头像*/
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
/*用户头像底部约束*/
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *iconImageViewBottom;
/*欢迎回来*/
@property (weak, nonatomic) IBOutlet UILabel *welcomeLabel;



@end

@implementation YDYWelcomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}
-(void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    [self setupUI];
    
    [self startAnimation];
    
}
-(void)setupUI{
    self.iconImageView.layer.cornerRadius = 45;
    self.iconImageView.layer.masksToBounds = YES;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:[YDYUserAccount sharedAccount].avatar_large]];
}
-(void)startAnimation{
    
    self.iconImageViewBottom.constant = [UIScreen mainScreen].bounds.size.height -  self.iconImageViewBottom.constant;
    [UIView animateWithDuration:1.5 animations:^{
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:2 animations:^{
            self.welcomeLabel.alpha = 1.0;
        } completion:^(BOOL finished) {
            [[NSNotificationCenter defaultCenter]postNotificationName:YDYChangeRootViewControllerNotification object:self];
//            [self jumoToMainController];
        }];
    }];
    
}
-(void)jumoToMainController{
    
    [UIApplication sharedApplication].keyWindow.rootViewController = [UIStoryboard storyboardWithName:@"Main" bundle:nil].instantiateInitialViewController;
}
@end
